package weifei.live.simulation.service;


import com.auth0.jwt.JWT;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import weifei.live.simulation.entity.Adminer;

@Service
public class AdminerService
{
    private final Adminer dao_adminer = new Adminer();

    public Integer getAdminerIDByToken(String token)
    {
        return JWT.decode(token).getClaim("adminerID").asInt();
    }


    public Adminer getAdminerByToken(String token)
    {
        var adminer_id = JWT.decode(token).getClaim("adminerID").asInt();
        if (adminer_id == null)
            return null;
        return this.getAdminerByID(adminer_id);
    }


    public Adminer getAdminerByID(int adminerId)
    {
        QueryWrapper<Adminer> qw_adminer = new QueryWrapper<>();
        qw_adminer.eq(Adminer.Column.ID.getName(), adminerId);
        return this.dao_adminer.selectOne(qw_adminer);
    }


}





